import time
from flask import Flask,jsonify,request
from utils.jwtc import myjwt
app = Flask(__name__)


from config import Config
from flask_cors import CORS
from views.course import bp_course
from views.adminuser import bp_auser
app.config.from_object(Config)
CORS(app)
app.register_blueprint(bp_course)
app.register_blueprint(bp_auser)


@app.before_request
def before_request():
    white = ['/login','/sendsms']
    #获取token
    if request.path not in white:
        #  token = request.headers['Token']
        token = myjwt.jwt_encode(data={'data':{'id':1,'iat':time.time(),'exp':3600}})
        if not token:
            return jsonify({'code':403,'mes':'无权访问'})
        payload = myjwt.jwt_decode(token)
        # 创建时间
        ctime = payload['data']['iat']
        # 设置token时间
        extime = payload['data']['exp']
        if int(time.time()-ctime)>extime:
              

    # token是否过期
    # 解析token


if __name__ == '__main__':
    app.run()

    
    